package com.shz.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ListComparator {

    public static void main(String[] args) {
        List<String> list1 = Arrays.asList("a", "b", "c");
        List<String> list2 = Arrays.asList("a", "c","b");

        boolean areEqual = compareListsUsingSort(list1, list2);
        System.out.println("Lists are equal: " + areEqual);
    }

    /**
     * 比较两个 List<String> 是否完全相同
     *
     * @param list1 第一个列表
     * @param list2 第二个列表
     * @return 如果两个列表完全相同返回 true，否则返回 false
     */
    public static boolean compareListsUsingSort(List<String> list1, List<String> list2) {
        if (list1.size() != list2.size()) {
            return false;
        }

        List<String> sortedList1 = new ArrayList<>(list1);
        List<String> sortedList2 = new ArrayList<>(list2);

        Collections.sort(sortedList1);
        Collections.sort(sortedList2);

        return sortedList1.equals(sortedList2);
    }
    public static boolean compareList(List<String> list1, List<String> list2) {
        if (list1.size() != list2.size()) {
            return false;
        }

        List<String> sortedList1 = new ArrayList<>(list1);
        List<String> sortedList2 = new ArrayList<>(list2);


        return sortedList1.equals(sortedList2);
    }
}